package com.mao.utils.compare;

import java.util.ArrayList;
import java.util.List;

/**
 * 类注释
 *
 * @author maorui
 * @date Created in 2023/10/27 10:27
 **/
public class compareUtils {

    /**
     * 对比两个List<String>的差异
     */
    public static void compareDifferences(List<String> list1, List<String> list2) {

        // 获取list1中存在但list2中不存在的元素
        List<String> diff1 = new ArrayList<>(list1);
        diff1.removeAll(list2);
        System.out.println(diff1);

        // 获取list2中存在但list1中不存在的元素
        List<String> diff2 = new ArrayList<>(list2);
        diff2.removeAll(list1);
        System.out.println(diff2);

        // 获取两个列表中都存在的元素
        List<String> common = new ArrayList<>(list1);
        common.retainAll(list2);
        System.out.println(common);

    }
}
